package main

import (
	"fmt"
	"strings"
)

//字符串操作
func main() {

	str := " 我是王镇涛,我爱吃杨梅,王镇涛 "

	var str2 [] string  = []string{"foo", "bar", "baz"}
	fmt.Println("Join= " , strings.Join(str2, "; "))

	fmt.Println("IndexAny = ", strings.IndexAny(str,"王"))
	fmt.Println("Index = ", strings.Index(str,"王"))

	//重复
	repeat := strings.Repeat(str, 2)

	fmt.Println("Repeat = ", repeat)

	compare := strings.Compare(str, str)

	fmt.Println("Compare = ", compare)

	//包含
	contains := strings.Contains(str, "王镇涛")

	fmt.Println("contains = " , contains)

	//功能：在s字符串中，把old字符串替换为new字符串，n表示替换的次数，小于0表示全部替换
	replace := strings.Replace(str, "王", "杨", 1)

	fmt.Println("Replace = ", replace)

	//功能：在s字符串的头部和尾部去除cutset指定的字符串
	trim := strings.Trim(str, " ")

	fmt.Println("trim = " , trim)

	//功能：去除s字符串的空格符，并且按照空格分割返回slice
	fmt.Printf("Fields are: %q", strings.Fields("  foo bar  baz   "))
}
